package Layouts 
{
	import flash.display.Sprite;
	import flash.display.Bitmap;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.*;
	
	public class WinMenu extends Sprite 
	{
		[Embed(source="../Resources/Texts/kidfont.ttf", fontName = "Kidfont",
		fontStyle = "normal" ,fontWeight = "bold", embedAsCFF= "false")]
		private static var font:Class;
		private var text_format1:TextFormat;
		private var text_format2:TextFormat;
		private var message:TextField;
		private var text:TextField;
		
		[Embed(source = "../Resources/Images/Entities/Ardilla_Logo.png")]
		private var logo:Class;
		
		private var par:Main;
		
		private var bg:Sprite = new Sprite();
		private var imgcont:Sprite = new Sprite();		
		private var msgcont:Sprite = new Sprite();
		private var backbutton:Sprite = new Sprite();
		
		public function WinMenu(parent:Main):void
		{
			addEventListener(Event.ADDED_TO_STAGE, init);
			par = parent;
		}
		private function init(e:Event):void {
			removeEventListener(Event.ADDED_TO_STAGE, init);
			
			var W:uint = stage.stageWidth;
			var H:uint = stage.stageHeight;
			
			bg.graphics.clear();
			bg.graphics.beginFill(0xFCF089);
			bg.graphics.drawRect(0 , 0, W, H);
			bg.graphics.endFill();
			addChild(bg);
			
			imgcont.graphics.clear();
			imgcont.graphics.beginFill(0xC99837);
			imgcont.graphics.drawRoundRect(0, 0, W / 3, W / 3, W/9);
			imgcont.graphics.endFill();
			addChild(imgcont);
			imgcont.x = W / 13,
			imgcont.y = W / 9;
			
			var img:Bitmap = new logo();
			imgcont.addChild(img);
			img.scaleX = 0.8;
			img.scaleY = 0.8;
			img.x = imgcont.width / 2 - img.width / 2;
			img.y = imgcont.height / 2 - img.height / 2;
			
			msgcont.graphics.clear();
			msgcont.graphics.beginFill(0xC99837);
			msgcont.graphics.drawRoundRect(0, 0, W * 5 / 12, W * 2/ 9, W /9);
			msgcont.graphics.endFill();
			addChild(msgcont);
			msgcont.x = W / 2,
			msgcont.y = W * 3 / 18;
			
			backbutton.graphics.clear();
			backbutton.graphics.beginFill(0xC99837);
			backbutton.graphics.drawRoundRect(0, 0, W * 2/3, H / 8, H / 16);
			backbutton.graphics.endFill();
			addChild(backbutton);
			backbutton.x = W / 6;
			backbutton.y = W * 4 / 9 + (H - W * 4 / 9) / 2 - H / 16;
			backbutton.buttonMode = true;
			backbutton.useHandCursor = true;
			backbutton.addEventListener(MouseEvent.CLICK, back_click);
			
			text_format1 = new TextFormat();
			text_format1.font = "Kidfont";
			text_format1.size = 50;
			
			text_format2 = new TextFormat();
			text_format2.font = "Kidfont";
			text_format2.size = 30;
			
			text = new TextField();
			text.embedFonts= true;
			text.defaultTextFormat = text_format1;
			text.selectable = false;
			text.autoSize = TextFieldAutoSize.LEFT;
			text.text = "Regresar";
			backbutton.addChild(text)
			text.x = backbutton.width/2 - text.textWidth/2;
			text.y = backbutton.height / 2 - text.textHeight / 2;
			
			message = new TextField();
			message.embedFonts= true;
			message.defaultTextFormat = text_format2;
			message.selectable = false;
			message.autoSize = TextFieldAutoSize.LEFT;
			message.text = "Felicitaciones! Ganaste el juego!";
			msgcont.addChild(message)
			message.x = msgcont.width/2 - message.textWidth/2;
			message.y = msgcont.height / 2 - message.textHeight / 2;
			
		}
		private function back_click(e:MouseEvent):void {
			par.screen_manager.goToScreen("MainMenu");
			par.screen_manager.game_files.data.finished_game = true;
		}
	}
}